﻿@model EvalResultVM
@{
    ViewData["Title"] = "评教页面";
}
@section Css{
<link rel="stylesheet" href="~/css/assessment.css" asp-append-version="true">
}

<div class="content">
    <h2>请根据问题给教师打分：</h2>
    <input id="count" type="hidden" value="@Model?.QuesInfos.Count" />
    <div class="content-table">
        @await Html.PartialAsync("QuestionsTable")
    </div>
    @if (!Model.IsEvaluate)
    {
        <div class="tijiao">
            <a class="btn btn-primary btn-sm" style="background:#a9161f;border:0;padding:4px 20px" id="submit">提交</a>
        </div>
    }

    <div class="input-group mb-3" style="width:80%;margin: 0 auto;margin-top:50px;height:80px;">
        <input id="input_comment" type="text" class="form-control" placeholder="评论信息" aria-label="评论信息" aria-describedby="button-addon2">
        <a class="btn btn-outline-secondary" id="send_comment">发送</a>
    </div>

    @await Html.PartialAsync("Comment")

</div>

@section Scripts{
<script>
    $(function(){
        var scId = getQueryVariable('scid');

        // 提交评教
        $("#send_comment").click(function(){
            let evals = getOptions();
            if(evals){
                let rid = "";
                let content = $("#input_comment").val();
                let data = {scId, rid, content};
                $.post("/api/Comment/Add",data,function(res,status,xhr){
                    if(res.suc && res.data > 0){
                        alert("提交成功");
                        window.location.reload();
                    }else{
                        console.log(res,status);
                    }
                });
            }
        });

        // 提交评教
        $("#submit").click(function(){
            let evals = getOptions();
            if(evals){
                let data = {scId:scId,evals:evals};
                $.get("/api/People/Eval",data,function(res,status,xhr){
                    if(res.suc){
                        alert("提交成功");
                        window.location.href = "/Student/Index";
                    }
                    console.log(res,status);
                });
            }
        });

        // 获取选项
        function getOptions(){
            let count = $('#count').val();
            let options = '';
            for(let i=1;i<=count;i++){
                let obj = $(`input:radio[name='grade+${i}']:checked`);
                let claimId = obj.data('claimid');
                let val = obj.val();
                options += `${claimId}_${val},`;
                if(!claimId || !val){
                    $(`#question_${i}`).show();
                    $('html, body').animate({scrollTop: $(`#question_${i}`).offset().top-200}, 1000);
                    return false;
                }else{
                    $(`#question_${i}`).hide();
                }
            }
            console.trace(options);
            return options;
        }

        // 获取query
         function getQueryVariable(key)
        {
           var query = window.location.search.substring(1);
           var vars = query.split("&");
           for (let i=0;i<vars.length;i++) {
                   var pair = vars[i].split("=");
                   if(pair[0] === key){return pair[1];}
           }
           return false;
        }
    });
</script>
}